package com.example.springboot_first.exception;

import com.example.springboot_first.pojo.ResponseMessage;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

@RestControllerAdvice   //统一处理异常
public class GlobalExceptionHandlerAdvice {
    Logger log= LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);
    @ExceptionHandler({Exception.class})//捕获所有异常
    public ResponseMessage<String> handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
        //记录异常信息
        log.error("统一异常：",  e);
        return new ResponseMessage(500,"error",null);
    }

}
